import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

class Input {
    static String line;     //一行的内容
    static String fileName; //文档路径
    static ArrayList<Building> buildings = new ArrayList<>();           //建筑名单
    static ArrayList<ArrayList<Integer>> timeTable = new ArrayList<>(); //班车时间表
    static ArrayList<course> coursesTable = new ArrayList<>();          //课表
    static ArrayList<myEdge> edges = new ArrayList<>();                 //边名单
    static HashMap<Integer,String> directionMap=new HashMap<>();        //方向转换

    static {    //初始化课表,班车时间表,方向转换表
        coursesTable.add(new course(1, 8, 0, "N-319", "计算机网络", 20));
        coursesTable.add(new course(1, 9, 5, "S-202", "计算机组成原理", 21));
        coursesTable.add(new course(1, 13, 0, "N-118", "Java程序设计", 20));
        coursesTable.add(new course(2, 13, 0, "N-201", "形式语言与自动机", 20));
        coursesTable.add(new course(2, 14, 4, "N-209", "毛概", 20));
        coursesTable.add(new course(3, 8, 0, "N-105", "计算机网络", 20));
        coursesTable.add(new course(4, 16, 3, "N-206", "毛概", 20));
        coursesTable.add(new course(5, 9, 5, "N-113", "数据结构课程设计", 20));

        timeTable.add(new ArrayList<>());
        timeTable.get(0).add(6);
        timeTable.get(0).add(5);
        timeTable.add(new ArrayList<>());
        timeTable.get(1).add(8);
        timeTable.get(1).add(3);
        timeTable.add(new ArrayList<>());
        timeTable.get(2).add(12);
        timeTable.get(2).add(0);
        timeTable.add(new ArrayList<>());
        timeTable.get(3).add(13);
        timeTable.get(3).add(3);
        timeTable.add(new ArrayList<>());
        timeTable.get(4).add(14);
        timeTable.get(4).add(2);
        timeTable.add(new ArrayList<>());
        timeTable.get(5).add(16);
        timeTable.get(5).add(5);

        directionMap.put(1,"北");
        directionMap.put(2,"东");
        directionMap.put(3,"东北");
        directionMap.put(4,"东南");
        directionMap.put(5,"西北");
        directionMap.put(6,"西南");
        directionMap.put(7,"西");
        directionMap.put(8,"南");
    }

    public static void InputBuildings(){    //从文件读入所有建筑
        Scanner sc = new Scanner(System.in);

        System.out.println("输入建筑文件路径");
        fileName = sc.next();//"C:\\Users\\86153\\Documents\\NavigationFiles\\Buildings3.txt";

        try {

            BufferedReader in=new BufferedReader(new FileReader(fileName));
            line=in.readLine();

            while (line!=null){

                Building building = new Building();
                String[] split=line.split(" "); //读入的内容按空格分开

                building.ID = Integer.parseInt(split[0]);
                building.Building_Name = split[1];
                building.Devices = new String[Integer.parseInt(split[2])];

                for(int i = 0; i < Integer.parseInt(split[2]); i++){    //录入设施,若表中没有这一项则新开一项

                    building.Devices[i] = (split[3 + i]);

                    if (!Navigation.DevicesMap.containsKey(building.Devices[i]))
                        Navigation.DevicesMap.put(building.Devices[i], new ArrayList<>());

                    Navigation.DevicesMap.get(building.Devices[i]).add(building);
                }

                buildings.add(building);    //添加到名单中

                line = in.readLine();
            }
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void InputEdges(){
        Scanner sc = new Scanner(System.in);

        System.out.println("输入边文件路径");
        fileName = sc.next();//"C:\\Users\\86153\\Documents\\NavigationFiles\\Edges2.txt";

        try {

            BufferedReader in=new BufferedReader(new FileReader(fileName));
            line=in.readLine();

            while (line!=null){ //输入边与反向边

                myEdge edge = new myEdge();
                myEdge edgeT = new myEdge();

                String[] split=line.split(" "); //按空格分开

                edge.Start = Integer.parseInt(split[0]);
                edge.End = Integer.parseInt(split[1]);
                edge.Weight = Integer.parseInt(split[2]);
                edge.Volume = Integer.parseInt(split[3]);
                edge.Bicycle = Boolean.parseBoolean(split[4]);
                edge.Direction = Integer.parseInt(split[5]);

                edges.add(edge);

                edgeT.Start = edge.End;
                edgeT.End = edge.Start;
                edgeT.Weight = edge.Weight;
                edgeT.Volume = edge.Volume;
                edgeT.Bicycle = edge.Bicycle;
                edgeT.Direction = 9 - edge.Direction;   //方向存储为整型,相对方向(如南,北)相加为9,方便得出反向边的数据

                edges.add(edgeT);

                line=in.readLine();
            }
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
